﻿using System;
using System.IO;
using System.Configuration;

namespace Attendences.Server.Biz
{
    public class LogHelper
    {
        public static void WriteLog(string Log)
        {

            string dic = ConfigurationManager.AppSettings["LogPath"];
            //  string dic = "d:\\\\log\\\\";
            if (!dic.EndsWith("\\"))
                dic += "\\";
            dic += "log\\";
            if (!Directory.Exists(dic))
                Directory.CreateDirectory(dic);
            string FileName = dic + DateTime.Now.ToString("yyyyMMdd") + ".log";
            FileStream fs = new FileStream(FileName, FileMode.Append);
            StreamWriter streamWriter = new StreamWriter(fs);
            streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            streamWriter.WriteLine(Log);
            //streamWriter.Flush();
            //fs.Flush();
            fs.Flush();

            streamWriter.Close();
            fs.Close();
            //if (!EventLog.SourceExists("myevent"))
            //    EventLog.CreateEventSource("myevent", "MyEvent");
            //EventLog.WriteEntry("myevent", Log, EventLogEntryType.Error);


        }
    }
}
